﻿<%@ Page Title="" Language="C#" MasterPageFile="~/SIPO.master" AutoEventWireup="false"
    CodeFile="recAcceptancelist.aspx.cs" Inherits="SIPO.Web.Lists.Transaction.recAcceptancelist" %>

<asp:Content ID="Content1" ContentPlaceHolderID="body" runat="Server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveUrl("~/styles/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/i18n/grid.locale-id.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveUrl("~/scripts/jquery.jqGrid.min.js") %>"></script>
    <div>
        <button id="btnAdd" type="button" onclick="OpenForm('add');">
            Tambah</button>
        <button id="btnEdit" type="button" onclick="OpenForm('edit');">
            Ubah</button>
        <button id="btnReview" type="button" onclick="OpenForm('review');">
            Setujui</button>
        <button id="btnView" type="button" onclick="OpenForm('view');">
            Lihat</button>
        <button id="btnOpen" type="button" onclick="OpenForm('open');">
            Buka</button>
    </div>
    <br />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog1" title="Default dialog">
    </div>
    <script type="text/javascript">

        $("#btnAdd").button({ icons: { primary: "ui-icon-plus"} });
        $("#btnEdit").button({ icons: { primary: "ui-icon-pencil"} });
        $("#btnReview").button({ icons: { primary: "ui-icon-locked"} });
        $("#btnView").button({ icons: { primary: "ui-icon-folder-open"} });
        $("#btnOpen").button({ icons: { primary: "ui-icon-unlocked"} });

    </script>
    <script type="text/javascript">

        var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Transaction/recAcceptancehandler.ashx") %>';

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['ID', 'Tahun', 'Versi', 'No. Surat', 'Tgl. Surat', 'Tgl. Simpan Penerimaan', 'Tgl. Persetujuan Penerimaan', 'IsMax', 'Total Target Penerimaan (Rp)'],
            colModel: [
                    { name: 'AcceptanceId', hidden: true, index: 'AcceptanceId', width: 0 },
                    { name: 'AcceptancePeriod', searchtype: 'number', index: 'AcceptancePeriod', align: 'center', width: 85 },
                    { name: 'Versi', index: 'Versi', searchtype: 'number', align: 'center', width: 30 },
                    { name: 'SkNo', index: 'SkNo', search: false, align: 'center', width: 0 },
                    { name: 'SkDate', search: false, index: 'SkDate', align: 'center', width: 85, formatter: 'date', formatoptions: { newformat: 'd M Y'} },
                    { name: 'EntryDate', search: false, index: 'EntryDate', align: 'center', width: 85, formatter: 'date', formatoptions: { newformat: 'd M Y'} },
                    { name: 'ReviewDate', search: false, index: 'ReviewDate', align: 'center', width: 140, formatter: 'date', formatoptions: { newformat: 'd M Y'} },
                    { name: 'UpdatedBy', hidden: true, index: 'UpdatedBy', width: 60 },
                    { name: 'sumValues', searchtype: 'number', searchtype: 'number', index: 'sumValues', formatter: 'number', align: 'right', width: 120 }

           	],
            rowNum: 10,
            id: 'AcceptanceId',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'AcceptancePeriod',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 1150,
            height: '100%',
            caption: 'Target Penerimaan',
            ajaxGridOptions: { cache: false },
            beforeSelectRow: function (rowid, e) {
                $('#table').jqGrid('resetSelection');
                return (true);
            }
        });

        $("#table").jqGrid('navGrid', '#pager', { edit: false, add: false, del: false, searchtext: 'Search', refreshtext: 'Refresh' },
        {}, {}, {}, { closeOnEscape: true, multipleSearch: true, closeAfterSearch: true, showQuery: false });


        function OpenForm(ctl) {
            var formUrl = '<%= ResolveUrl("~/forms/Transaction/recAcceptanceform.aspx") %>';

            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            selisReview = [];
            selisMax = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'AcceptanceId'));
                selisReview.push(grid.jqGrid('getCell', this, 'ReviewDate'));
                selisMax.push(grid.jqGrid('getCell', this, 'UpdatedBy'));
            });
            if (ctl == 'edit') {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di ubah!');
                else {
                    if (selIds.length > 1) {
                        alert('Pilih satu record untuk ubah data!');
                    }
                    else if (selisMax != 'max') {
                        alert("Hanya data versi terakhir yang dapat di ubah!");
                    }
                    else if (selIds.length == 1 && selisReview.toString().toLowerCase().indexOf('2') < 0) {
                        $('#dialog1').load(formUrl + '?id=' + selText).dialog({ autoOpen: false, modal: true, width: 650, title: 'Ubah Target Penerimaan' });
                        $("#dialog1").dialog('open');
                    }
                    else {
                        alert("Data yang anda pilih tidak dapat di ubah !");
                    }
                }
            }
            else if (ctl == 'add') {
                $('#dialog1').load(formUrl).dialog({ autoOpen: false, modal: true, width: 650, title: 'Input Target Penerimaan' });
                $("#dialog1").dialog('open');
            }
            else if (ctl == 'review') {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di setujui!');
                else {
                    if (selIds.length > 1) {
                        alert('Pilih satu record untuk ubah persetujuan!');
                    }
                    else if (selisMax != 'max') {
                        alert("Hanya data versi terakhir yang dapat di setujui!");
                    }
                    else if (selIds.length == 1 && selisReview.toString().toLowerCase().indexOf('2') < 0) {
                        $('#dialog1').load(formUrl + '?id=' + selText + '&review=1').dialog({ autoOpen: false, modal: true, width: 650, title: 'Persetujuan Target Penerimaan' });
                        $("#dialog1").dialog('open');
                    }
                    else {
                        alert("Data yang anda pilih tidak dapat di setujui !");
                    }
                }
            }
            else if (ctl == 'open') {
                if (selIds.length > 1) {
                    alert('Pilih hanya satu record !');
                }
                else {
                    if (selIds.length == 0)
                        alert('Pilih data yang mau di buka!');
                    else {
                        if (selIds.length == 1 && selisReview.toString().toLowerCase().indexOf('2') >= 0) {
                            var result = window.confirm('Apakah Anda yakin untuk mengubah data ini?');
                            if (result) {
                                var obj = new Object();
                                jsonData = JSON.stringify(obj);
                                CallAjax('<%= ResolveUrl("~/AjaxHandler/Transaction/recAcceptancehandler.ashx") %>', "?method=open&acceptanceid=" + selText, jsonData);

                                setTimeout("$('#table').trigger('reloadGrid');", 3000);
                            }
                        }
                        else {
                            alert("Data yang anda pilih belum di setujui !");
                        }
                    }
                }

            }
            else {
                if (selIds.length == 0)
                    alert('Pilih data yang mau di lihat!');
                else {
                    if (selIds.length > 1) {
                        alert('Pilih satu record untuk lihat data!');
                    }
                    else if (selIds.length == 1) {
                        $('#dialog1').load(formUrl + '?id=' + selText + '&view=1').dialog({ autoOpen: false, modal: true, width: 650, title: 'Lihat Target Penerimaan' });
                        $("#dialog1").dialog('open');
                    }
                }
            }
        }
    </script>
</asp:Content>
